<?php

namespace App\Http\Requests;

use Dotenv\Validator;
use Illuminate\Foundation\Http\FormRequest;

class CheckUser extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;



    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
            'name' => 'required',
            'password' => 'required',
            'email' => 'required',
            'realname' => 'required',
            'tel' => 'required',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '账号不能为空!',
            'password.required' => '密码不能为空',
            'email.required' => '邮箱不能为空',
            'realname.required' => '姓名不能为空',
            'tel.required' => '电话不能为空',
        ];
    }
//    ajax返回

    public function failedValidation(Validator $va)
    {
        throw (new \HttpRequestException(response()->json([
            'code' => 1,
            'msg' => $va->errors()->first(),
        ],0)));


    }
}
